﻿/*
 * 日 期：2017.03.22
 * 描 述：个人中心
 */
var baseinfo;
var bootstrap = function ($, learun) {
    "use strict";

    var index = request("index");

    var page = {
        init: function () {
            page.initleft();
            page.bind();
            page.initData();
        },
        bind: function () {
            if (!!index) {
                $('#lr_left_list li').each(function(){
                    var $this = $(this);
                    var curIndex = $this.attr("data-value");
                    if(curIndex == index){
                        var $parent = $this.parent();
                        $parent.find('.active').removeClass('active');
                        $this.addClass('active');
                        $('.lr-layout-wrap-item').removeClass('active');
                        $('#lr_layout_item' + index).addClass('active');
                    }
                });
            }
        },
        initleft: function () {
            $('#lr_left_list li').on('click', function () {
                var $this = $(this);
                if (!$this.hasClass('active')) {
                    var $parent = $this.parent();
                    $parent.find('.active').removeClass('active');
                    $this.addClass('active');
                    var _type = $this.attr('data-value');
                    $('.lr-layout-wrap-item').removeClass('active');
                    $('#lr_layout_item' + _type).addClass('active');
                }
            });
        },
        initData: function () {
            learun.httpAsyncGet(config.base_server() + 'oauth/userinfo', function (data) {
                if (data) {
                    baseinfo = data.user;
                    /*基础信息*/
                    $('#userName').val(baseinfo.userName);
                    $('#phone').val(baseinfo.phone);
                    $('#realName').val(baseinfo.realName);
                    $('#sex').val(baseinfo.sex == 0 ? '女' : '男');
                    learun.clientdata.getAsync('company', {
                        key: baseinfo.companyId,
                        callback: function (_data) {
                            $('#company').val(_data.name);
                        }
                    });

                    learun.clientdata.getAsync('department', {
                        key: baseinfo.departmentId,
                        callback: function (_data) {
                            $('#department').val(_data.name);
                        }
                    });
                    learun.httpAsyncGet(config.base_server() + 'posts/getNames?keyValue=' + baseinfo.postIds, function (res) {
                        $('#post').val(res.data);
                    });
                    learun.httpAsyncGet(config.base_server() + 'roles/getNames?keyValue=' + baseinfo.roleIds, function (res) {
                        $('#role').val(res.data);
                    });
                    $('#description').val(baseinfo.description);
                } else {
                    learun.alert.error('数据加载失败');
                }
            });
        }
    };


    page.init();
}


